﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

/// <summary>
/// Abstract Class UserControlBaseClass
/// Overwrite in new class: Protected override void Page_Init(object sender, EventArgs e) {}
/// </summary>
public abstract class UserControlBaseClass : System.Web.UI.UserControl {
	private string _userId = "";
	private string _sessionId = "";
	private AccountProvider _ap = new AccountProvider();

	/// <summary>
	/// Get or set the UserId
	/// </summary>
	public string UserId {
		get {
			if(this._userId == "") {
				object o = Session["ZapprUserId"];

				if(o != null) {
					this._userId = o.ToString();
				}
				else {
					this._userId = "";
				}
			}
			return this._userId;
		}
		set { Session["ZapprUserId"] = value; }
	}

	/// <summary>
	/// Get or set the UserId
	/// </summary>
	public string SessionId {
		get {
			if(this._sessionId == "") {
				object o = Session["Zappr"];

				if(o != null) {
					this._sessionId = o.ToString();
				}
				else {
					this._sessionId = "";
				}
			}
			return this._sessionId;
		}
		set { Session["Zappr"] = value; }
	}

	/// <summary>
	/// Page_Init
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Init(object sender, EventArgs e) {
		if(this.UserId == ""
		|| this.SessionId == ""
		|| Session.Count == 0) {
			Response.Redirect("~/Login.aspx", true);
		}
	}
}
